package com.jiangkang.example.mapper;

import com.jiangkang.example.dto.UserPartialInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author fang
 * @describe 用户相关操作的接口
 * @date 2019-03-11
 */
public interface UserMapper {

	/**
	 * 根据unionid批量查询，得到UserPartialInfos
	 */
	@Select("<script>"
	        +"select unionid,nickname,mobile,student_id   "
	        +"from t_user   "
			+"where unionid in "
			+ "<foreach collection='unionIds' index='index' item='uids' open='('  separator=',' close=')'> "
			+ " #{uids} "
	        +"</foreach>"
			+"</script>")
	@Results({ @Result(property = "nickname", column = "nickname"),
		       @Result(property = "mobile", column = "mobile"),
			   @Result(property = "studentId", column = "student_id"),
			   @Result(property = "unionId", column = "unionid"),
			   })
	List<UserPartialInfo> batchQueryUserPartialInfoByUnionIds(@Param("unionIds") List <String> unionIds);


	/**
	 * 根据studentId，得到UserPartialInfos
	 */
	@Select("select unionid,nickname,mobile,student_id from t_user where student_id=#{studentId} ")
	@Results({ @Result(property = "nickname", column = "nickname"),
		       @Result(property = "mobile", column = "mobile"),
			   @Result(property = "studentId", column = "student_id"), 
			   @Result(property = "unionId", column = "unionid"), 
			   })
	UserPartialInfo queryUserByStudentId(@Param("studentId") String studentId);


}
